package top.hkyzf.study.leetcode.array;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

/**
 * description: 
 * @author zhufeng
 * @date 2024/3/28 0028 10:37
 * @version V1.0
 */
public class 访问完所有房间的第一天_1997 {
    public int firstDayBeenInAllRooms(int[] nextVisit) {
        final long MOD = 1_000_000_007;
        int n = nextVisit.length;
        long[] s = new long[n];
        for (int i = 0; i < n - 1; i++) {
            int j = nextVisit[i];
            s[i + 1] = (s[i] * 2 - s[j] + 2 + MOD) % MOD; // + MOD 避免算出负数
        }
        return (int) s[n - 1];
    }

    @Test
    public void testFirstDay () {
        int[] nextVisit = {0,0};
        System.out.println(firstDayBeenInAllRooms(nextVisit));
    }
}
